package prepare.huawei;

import java.util.Scanner;

/**
 * description: <a href="https://www.nowcoder.com/practice/66ca0e28f90c42a196afd78cc9c496ea?tpId=37&tqId=21256&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=">整数与IP地址间的转换</a>
 *
 * @author <a href="zhaoyingling12@163.com">simon zhao</a>
 * @since 2023/3/28
 */
public class ConvertBetweenIntegersAndIP {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] ss = in.nextLine().split("\\.");
        long intIp = Long.parseLong(in.nextLine());
        String strBinaryNum = "";
        for (String s : ss) {
            strBinaryNum += getBinaryStr(s, 8);
        }

        char[] ipBinaryChs = getBinaryStr(String.valueOf(intIp), 32).toCharArray();
        String strIp = "";
        for (int i = 0; i < ipBinaryChs.length; i++) {
            String tmp = "";
            for (int index = i; index < i + 8; index++) {
                tmp += ipBinaryChs[index];
            }
            if (i == 0) {
                strIp += Integer.parseInt(tmp, 2);
            } else {
                strIp += "." + Integer.parseInt(tmp, 2);
            }
            i = i + 7;
        }
        System.out.println(Long.parseLong(strBinaryNum, 2));
        System.out.println(strIp);
    }

    private static String getBinaryStr(String intStr, int length) {
        long num = Long.parseLong(intStr);
        long[] bits = new long[length];
        int index = length - 1;

        while (num != 0) {
            bits[index--] = num % 2;
            num = num / 2;
        }
        String res = "";
        for (long bit : bits) {
            res += bit;
        }
        return res;
    }
}
